package demo.practice.competition;

import java.util.*;

public class P5831 {

    public static void main(String[] args) {
        P5831 p5831 = new P5831();
        //9,3,6,8,2,1   9,8,6,3,2,1            0, 1, 2, 3, 4 ,5
        //[5,7,5,7,9,7]
        long l = p5831.numberOfWeeks(new int[]{5, 5, 7, 7, 7, 9});
        System.out.println(l);
    }

    public long numberOfWeeks(int[] milestones) {
        ArrayList<Integer> list = new ArrayList<>();
        long sum = 0;
        for (int m : milestones) {
            list.add(m);
            sum += m;
        }
        Integer max = Collections.max(list);
        if (max > (sum - max)) {
            return 2 * (sum - max) + 1;
        } else {
            return sum;
        }
    }
}
